﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BEPUphysics.Entities;
using BEPUphysics;

namespace MagicArenaFramework.GameObject.Components.ConcreteTypes
{
    /// <summary>
    /// Component which holds a BepuPhysics entity.
    /// The isActive method handles add the Entity to the Space
    /// </summary>
    public class EntityComponent : GoComponent
    {
        public Entity Entity { get; private set; }
        public Space Space { get; private set; }

        public EntityComponent(Entity entity, Space space)
        {
            Entity = entity;
            Space = space;
        }

        public override bool isActive
        {
            get
            {
                return base.isActive;
            }
            set
            {
                // if value changed, add or remove accordingly
                if (value != isActive)
                {
                    if (value == true)
                    {
                        try
                        {
                            Space.Add(Entity);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    else Space.Remove(Entity);
                }
                base.isActive = value;
            }
        }
    }
}
